package com.srb.base.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 通过过滤器正则匹配进行swagger分组管理
 */
@EnableSwagger2
@Configuration
public class Swagger2Config {

    @Bean
    public Docket adminApiConfig(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.groupName("adminApi")
                .apiInfo(adminApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
        return docket;
    }

    @Bean
    public Docket webApiConfig(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
        return docket;
    }

    /**
     * 信息描述
     * @return
     */
    private ApiInfo webApiInfo(){
        ApiInfo apiInfo = new ApiInfoBuilder().title("尚融宝网站API文档")
                .description("本文档描述尚融宝网站的各个模块的接口调用")
                .version("1.6")
                .contact(new Contact("Alice", "http://www.atguigu.com", "test@123.com"))
                .build();
        return apiInfo;
    }

    /**
     * 信息描述
     * @return
     */
    private ApiInfo adminApiInfo(){
        ApiInfo apiInfo = new ApiInfoBuilder().title("尚融宝后台管理系统API文档")
                .description("本文档描述尚融宝后台管理系统的各个模块的接口调用")
                .version("1.6")
                .contact(new Contact("Helen", "http://www.atguigu.com", "test@123.com"))
                .build();
        return apiInfo;
    }
}
